package View;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ImageIcon;
import javax.swing.JComponent;

import Model.Spieler;

public class SpielerVC extends JComponent implements Observer{
	
	private int posX;
	private int posY;
	private Image image;
	private Spieler spielerModel;
	
	
	public SpielerVC(int posX, int posY, String imageName,Spieler spielerModel) {
		
		this.posX = posX;
		this.posY = posY;
		this.image=new ImageIcon(imageName).getImage();
		this.spielerModel=spielerModel;
		
		
		Dimension size = new Dimension(image.getWidth(this),
				image.getHeight(this));
				setPreferredSize(size);
				setMinimumSize(size);
				setMaximumSize(size);
				setSize(size);
	}
	
	public void syncViewToModel(){
		
		this.posX=spielerModel.getPosX();
		this.posY=spielerModel.getPosY();
		
		repaint();
	}

	
	public void update(Observable ob, Object o) {
		
		syncViewToModel();
		System.out.println("View SpielerX: "+posX);
		System.out.println("View SpielerY: "+posY);
		
	}
	

	public int getPosX() {
		return posX;
	}

	public int getPosY() {
		return posY;
	}

	public Image getImage() {
		return image;
	}
	

	public void draw(Graphics g){
		 
		super.paintComponents(g);
		g.drawImage(image, posX,posY,null);
		
		}
	
	}

	
	
	


